package com.zhizuobiao.class4.controller;

/**
 * Created by chengweixin on 2018/3/23.
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


@Controller
public class UploadController {

    @RequestMapping("/upload")
    @ResponseBody
    public String myUpload(
            @RequestParam(value = "uploadFile", required = true) MultipartFile file) throws IOException {

        System.out.println("file = " + file);

        long fileSize = file.getSize();

        System.out.println("fileSize =" + fileSize);


        // 可以再tomcat里面配置honst 虚拟路径 path ， base。。
        // 启动在intellj 打钩

        // 保存路径
        String savePath = "D:\\";

        // 文件名称
        String filename = file.getOriginalFilename();

        // 保存的文件
        File saveFile = new File(savePath, filename);

        // 调用保存文件方法
        file.transferTo(saveFile);


        return "success";
    }
}
